<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>仓储物资智能管理跟踪系统</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
<meta http-equiv="description" content="this is my page"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="../../head.js"></script>
</head>
<body>
	<div id="tools" class="datagrid-toolbar">
		<a onclick="add();"  class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
		<a onclick="edit();" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
		<a onclick="del();"  class="easyui-linkbutton" iconCls="icon-cancel" plain="true">删除</a>
		<a onclick="upStatus(1);"  class="easyui-linkbutton" iconCls="icon-loss" plain="true">禁用</a>
		<a onclick="upStatus(0);"  class="easyui-linkbutton" iconCls="icon-nook" plain="true">启用</a>
		<a onclick="showPass();"   class="easyui-linkbutton" iconCls="icon-work" plain="true">修改密码</a>
    </div>

	<div id="search" class="datagrid-toolbar" >
		<table>
			<tr>
				<td align="right">用户号：</td>
				<td align="left"><input name="username" id="username" value=""/></td>
				<td align="right">用户真实姓名：</td>
				<td align="left"><input name="truename" id="truename" value=" "/></td>
				<td align="right">用户状态：</td>
				<td align="left"><select name="status">
						<option value="-1">==全部==</option>
						<option value="0">启用</option>
						<option value="1">禁用</option>
				</select></td>
				<td><a class="easyui-linkbutton" iconCls="icon-search"
					plain="true" onclick="query();">确定</a> <a class="easyui-linkbutton"
					iconCls="icon-cancel" plain="true" onclick="requery();">清空</a></td>
			</tr>
		</table>
	</div>
	<div id="upPass" class="easyui-dialog" title="密码修改"
		style="padding: 5px; width: 400px; height: auto;"
		buttons="#btn-buttons" resizable="true" modal="true" closed="true">
		<table>
			<tr height="30">
				<td align="right" width="130">新密码：</td>
				<td align="left"><input type="password" name="newPass" id="newPass" />
				</td>
			</tr>
			<tr>
				<td align="right">重复密码：</td>
				<td align="left"><input type="password" name="repeatPass" id="repeatPass" />
				</td>
			</tr>
		</table>
		<div id="btn-buttons">
			<a class="easyui-linkbutton" onclick="upPass();">确定</a> <a
				class="easyui-linkbutton" onclick="$('#upPass').dialog('close');">取消</a>
		</div>
	</div>

	<table id="list_data"></table>
</body>
</html>
<script>
	selectWorkshop();
	function selectWorkshop(){
		$("#workshopId").empty();
		$.post(contextPath+"/system/dataDictionary/getListByCode",
		  {'dataCode':"workshopCode",'depth':2},function(data){
		     $("#workshopId").append("<option value='-1'>--请选择--</option>");
		     if(data!=null && data.length>0){
		    	 for(var i=0;i<data.length;i++){
		    		 $("#workshopId").append("<option value='"+data[i]['id']+"'>"+data[i]['name']+"</option>"); 
		    	 }
		     }
		 });
	}
	var URL = contextPath+"/system/sysUsers";
	$('#list_data').datagrid({
		url:URL+"?i="+new Date().getTime(),
		fitColumns:true,
		singleSelect:false,
		rownumbers:true,
		pagination:true,
		sortName:'id',
		sortOrder:'desc',
		striped:true,
		onLoadSuccess:onLoadScroll,
		onDblClickRow:dbClick,//行的双击事件
		columns:[[
			{field:'id',checkbox:true,sortable:true},
			{field:'roleName',title:'权限级别',width:100,sortable:true,align:'center'},
			{field:'username',title:'用户名',width:100,sortable:true,align:'center'},
			{field:'nickname',title:'昵称',width:100,sortable:true,align:'center'},
			{field:'zhiwei',title:'职位',width:100,sortable:true,align:'center'},
			{field:'detail',title:'简介',width:100,sortable:true,align:'center'},
			{field:'sex',title:'性别',width:100,sortable:true,formatter:sexRenderer,align:'center'},
			{field:'tel',title:'电话',width:100,sortable:true,align:'center'},
			{field:'email',title:'邮箱',width:100,sortable:true,align:'center'},
			{field:'status',title:'用户状态',width:100,sortable:true,formatter:statusRenderer,align:'center'}
		]]
	});
	function sexRenderer(value,row,index){
		if(value==0){
			return "男";
		}else if(value==1){
			return "女";
		}else{
			return "未知性别";
		}
	}
	function teamRenderer(value,row,index){
		if(value!=null && value!="" ){
			if(value.length>10){
				return "<span title='"+value+"'>"+value+"</span>";
			}
			return value;
		}
		return "";
	}
	
	function contentRenderer(value,row,index){
		if(value!=null && value!="" ){
			if(value.length>10){
				return "<span title='"+value+"'>"+value+"</span>";
			}
			return value;
		}
		return "";
	}
	
	function statusRenderer(value,row,index){
		switch(value){
			case 0:
				return '<font color=#A2CD5A>启用</font>';
			case 1:
				return '<font color=#919191>禁用</font>';
		   	default:
		   		return '未知'+value;
		}
	}
	//添加的方法
	function add(){
		openWindow(contextPath+"/manager/system/sysUsers/sysUsers_add.html");
	}
	//修改的方法
	function edit(){
		var id = getId('#list_data','data');//获取选中的行
		if(id == ""){
			return;
		}
		openWindow(contextPath+"/manager/system/sysUsers/sysUsers_edit.html?id="+id);
	}
	//行的双击事件
	function dbClick(rowIndex,rowData){
		openWindow(contextPath+"/manager/system/sysUsers/sysUsers_edit.html?id="+rowData['id']);
	}
	
	//删除
	function del(){
		var ids = getIds('#list_data','data');//获取选中的行
		if(ids == ""){
			return;
		}
		$.messager.confirm('提示','确定要删除吗?',function(r){
			if(r){
				$.ajax({
					type : 'POST',
					url : contextPath+'/system/delSysUsers',
					data : {'ids':ids},
					dataType : "json",
					success : function(data){
						$.messager.alert("提示","操作成功!",'info',function(rt){
							query();
						});
					},
					error:function(response){
						$.messager.alert("提示","出错了，请联系管理员!",'error',function(rt){
							$.messager.alert("提示",response.responseText,'error');
						});
					}
				});
			}
		});
	}
	function upStatus(status){
		var mes = "";
		if(status==0){
			mes = "启用";
		}
		if(status==1){
			mes = "禁用";
		}
		var ids = getIds('#list_data','data');//获取选中的行
		if(ids == ""){
			return;
		}
		$.messager.confirm('提示','确定要'+mes+'吗?',function(r){
			if(r){
				$.ajax({
					type : 'POST',
					url : contextPath+'/system/upSysUsersStatus',
					data : {'ids':ids,'status':status},
					dataType : "json",
					success : function(data){
						$.messager.alert("提示","操作成功!",'info',function(rt){
							query();
						});
					},
					error:function(response){
						$.messager.alert("提示","出错了，请联系管理员!",'error',function(rt){
							$.messager.alert("提示",response.responseText,'error');
						});
					}
				});
			}
		});
	}
	//显示修改密码层
	function showPass(){
		var ids = getIds('#list_data','data');//获取选中的行ids
		if(ids == ""){
			return;
		}
		$('#newPass').val('');
		$('#repeatPass').val('');
		$('#upPass').dialog('open');
	}
	//修改密码事件
	function upPass(){
		var ids = getIds('#list_data','data');//获取选中的行ids
		if(ids == ""){
			return;
		}
		var newPass = $('#newPass').val();
		var repeatPass = $('#repeatPass').val();
		if(newPass == ""){
			$.messager.alert("提示","请输入密码!",'info');
			return;
		}
		if(newPass != repeatPass){
			$.messager.alert("提示","密码输入不一致!",'info');
			return;
		}
		
		$.ajax({
			type : 'POST',
			url : contextPath+'/system/upSysUsersPass',
			data : {'ids':ids,'password':newPass},
			dataType : "json",
			success : function(data){
				$.messager.alert("提示","操作成功!",'info',function(rt){
					$('#upPass').dialog('close');
					updateSearch();
				});
			},
			error:function(response){
				$.messager.alert("提示","出错了，请联系管理员!",'error',function(rt){
					$.messager.alert("提示",response.responseText,'error');
				});
			}
		});
	}
	//角色配置
	function user_role(){
		var id = getId('#list_data','data');//获取选中的行
		if(id == ""){
			return;
		}
		openWindow(contextPath+"/manager/system/sysUsers/sysUsers_role.html?id="+id);
	}
	//查询
	function query(){
		searchGo(URL+"?i="+new Date().getTime(),"#search","#list_data");
	}
	//清空
	function requery(){
		clearGo(URL+"?i="+new Date().getTime(),"#search","#list_data");
	}
	//更新、删除后调用的查询
	function updateSearch(){
		updateSearchGo(URL+"?i="+new Date().getTime(),"#search","#list_data");
	}
</script>		 
